
var objecttourcheck={};
var pagenewtrip=1;
var pagenewtripddddd=0;
function addformnewtour()
{
//alert('test');

    var rownow=rowdiv;
   $("#firstaddform").append(dataform['newtour1']);
   $("#firstaddform").append('<div class="featureclass">'+dataform['newtour']+'</div>');
   $("#pageaddfeature2").append(dataform['newtour2']);
   $("#pageaddfeature3").append(dataform['newtour3']);
  
  
  $( ' input[name="startdate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ' input[name="enddate[]"]' ).datepicker( "option", "minDate", selectedDate );
countdaydata();
}
});
  $( ' input[name="enddate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ' input[name="startdate[]"]' ).datepicker( "option", "maxDate", selectedDate );
        countdaydata();
}
});
   
   $('input[name="samecontactprofile[]"]').click(function() {
    
    if($(this).is(":checked"))
    {
    
    $.post(serviceinfo+'getmyuser', { select:['facebook','twitter','googleplus','email','website','phone','fax','etc'] }, function(data) {
    
    
           if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
          if(data['data']['facebook'])$('input[name="facebook[]"]').val(data['data']['facebook']); 
          if(data['data']['twitter'])$('input[name="twitter[]"]').val(data['data']['twitter']); 
          if(data['data']['googleplus'])$('input[name="googleplus[]"]').val(data['data']['googleplus']); 
          if(data['data']['email'])$('input[name="email[]"]').val(data['data']['email']);
          if(data['data']['website'])$('input[name="website[]"]').val(data['data']['website']);
          if(data['data']['phone'])$('input[name="phone[]"]').val(data['data']['phone']);
          if(data['data']['fax'])$('input[name="fax[]"]').val(data['data']['fax']);
          if(data['data']['etc'])$('textarea[name="etc[]"]').val(data['data']['etc']);
         
         }
    
    
    });
    
    }
    
    
    });
  
  
  
    $(".nextBtn").click(function() {
   
    if(pagenewtrip==1)
    {
    
     if($('#firstaddform input[name="title"]').val()=="")
    {
    boxmsgdata('Please Input Title');
    return false;
    }
    else if($('#firstaddform select[name="destination"]').val()=="")
    {
    
    boxmsgdata('Please Select Destination');
    return false;
    }
    else if($('#lastaddform input[name="imgmid[]"]').val()=="")
    {
    
    boxmsgdata('Please Select Thumbnail');
    return false;
    }
     
    $(".wrpBtnAddCtnt").addClass('wrpBtnAddTrip');
    $(".wrpBtnAddCtnt").addClass('clearfix');
    $(".wrpBtnAddCtnt").removeClass('wrpBtnAddCtnt');
    
    
    $(".nextBtn").addClass('btnNext');
    $(".wrpAuthUpdtAddCtnt").hide();
   $("#pageaddfeature1").hide();   
   $("#pageaddfeature2").show(); 
   $(".backBtn").show(); 
    pagenewtrip++;
    
    
    
    
    
    }
    else if(pagenewtrip==2)
    {
    
     if($('#pageaddfeature2 input[name="day[]"]').val()=="")
    {
    boxmsgdata('Please Input Day');
    return false;
    }
    else if(!is_numeric($('input[name="day[]"]').val()))
    {
        boxmsgdata('Please Input Day Numeric');
    return false;
    
    
    }
    
     else if($('#pageaddfeature2 input[name="startdate[]"]').val()=="")
    {
    
    boxmsgdata('Please Input StartDate');
    return false;
    }
    else if($('#pageaddfeature2 input[name="enddate[]"]').val()=="")
    {
    
    boxmsgdata('Please Input Enddate');
    return false;
    }
    
    $("#pageaddfeature2").hide();
    $("#pageaddfeature3").show();  

    $(".nextBtn").val('Finish');
    pagenewtrip++;
    
    
     var dayint=parseInt($('input[name="day[]"]').val(),10);
     
    if(is_numeric($('input[name="day[]"]').val())&&dayint>0&&$('input[name="startdate[]"]').val()!="")
    {
        var newrow=0;
        var nrow=$('.dateTripTmln').length;
        
        if(nrow==0)
        {
            newrow=dayint;
        
        }else if(dayint>nrow)
        {
           newrow= dayint-nrow;
        }else
        {
       // console.log(nrow);
      //  console.log(dayint);
           if(nrow>dayint)
           {
           var deleterow=nrow-dayint;
             
              for(var irow=0;irow<deleterow;irow++)
             {
             var nrow2=$('.dateTripTmln').length;
             $('.dateTripTmln').eq( nrow2-1 ).remove();
             
             }
           }
          
        
        }
    
      //  console.log(newrow);
        if(newrow)
        {

        
        var code='';
        var checkstate='dateTripTmlnAct';
        
        for(var irow=0;irow<newrow;irow++)
        {
        
        code +='<button type="button" class="dateTripTmln clTxtW clBgBt1 fs04 '+checkstate+'"></button>';

        checkstate='';
        }
        
        $("#pageaddfeature3 .btnDateTripTmln").append(code);
        
        }
        
    }
        
        
        var startdateset=$('input[name="startdate[]"]').val();
        var n0=startdateset.split("/"); 
        var d1 = new Date(n0[2],parseInt(n0[1],10)-1,parseInt(n0[0],10));
    
        var rownum=0;
        
        $( "#pageaddfeature3 .dateTripTmln").each(function( index ) {
        
            $(this).attr("id",'rowdaynumset-'+(rownum+1));
            //$(this).find('span.fs03').html('Day '+(rownum+1));
            $(this).html(startdateset);
            $(this).attr("onclick",'opentourdata('+(rownum+1)+')');
            
            
            

            d1.setTime(d1.getTime() +  ((0+1) * 24 * 60 * 60 * 1000));
            startdateset=d1.format("dd/mm/yyyy");
            
            rownum++;
        
        
        });
        
        opentourdata(1);
    //btnDateTripTmln
    
    
   //genmapnewtrip(); 
    }
    
    else if(pagenewtrip==3)
    {
    
    //$('#formaddfeature').submit();
    
    saveaddfeaturedata();


    }
    
    });
    
    $(".backBtn").click(function() {
    
    if(pagenewtrip==2)
    {

    $(".wrpBtnAddTrip").addClass('wrpBtnAddCtnt');
    $(".wrpBtnAddTrip").removeClass('clearfix');
    $(".wrpBtnAddTrip").removeClass('wrpBtnAddTrip');
        
        $(".nextBtn").removeClass('btnNext');
        $(".wrpAuthUpdtAddCtnt").show();
       $("#pageaddfeature1").show();   
       $("#pageaddfeature2").hide();
       $(".backBtn").hide(); 
       pagenewtrip--;
       
    } 
    else if(pagenewtrip==3)
    {
        $("#pageaddfeature2").show();
        $("#pageaddfeature3").hide(); 
        $(".nextBtn").val('Next');
        pagenewtrip--;

    }
    
    
    });
 
  
  var code = '<div class="popGenAddTrip posPopAddTrip">\n';
  code += '<div class="topGen clBd2 bdBtm">\n';
  code += '<div class="wrpTtlGen">\n';
  code += '<h1 class="ttlGen clTxt2 fs05">Add Trip</h1>\n';
  code += '</div>\n';
  code += '<div class="btnIco closeGen" onclick="$(\'.ovlPopGen.wrpPopAddNewTrip\').fadeOut();">\n';
  code += '<span class="ico icoCloseGen"></span>\n';
  code += '</div>\n';
  code += '<div class="topBgGen clBg3"></div>\n';
  code += '</div>\n';
  code += '<div class="bodyGen clBg3">\n';
  code += '<div class="bodyOutGen">\n';
    code += '<div class="bodyInGen">\n';
    code += '<div class="wrpTgHdGen clTxt2 fs04">\n';
    code += '<span class="tgHdGen tgCl clBd2 bdR clSp2" onclick="changecelltour(1)">My Posts</span>\n';
    code += '<span class="tgHdGen tgCl clBd2 bdR" onclick="changecelltour(2)">My Favorite</span>\n';
    code += '<span class="tgHdGen tgCl clBd2 " onclick="changecelltour(3)">Activity</span>\n';
    
    //code += '<span class="tgHdGen tgCl clBd2 bdR">New Post</span>\n';
    
    code += '<span class="tgHdGen tgCl clBd2 bdR" style="display:none">Recommend</span>\n';
    code += '<span class="tgHdGen tgCl clBd2" style="display:none">Search</span>\n';
    code += '</div>\n';
    code += '<div class="wrpFrmGenNewTrip">\n';
    code += '<div class="bodyAddNewTrip clBg4 clBd2 bdFull">\n';
    code += '<div class="wrpOutAddNewMyTrip">\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '<div class="wrpBtnGenNewTrip clearfix">\n';
    code += '<button type="button" class="btnGen btnOk clTxtW cutTxt clBgSp2 fs04" onclick="savetourbyselectdata()">ADD</button>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>';
    
    
    $(".ovlPopGen.wrpPopAddNewTrip").html(code);
  
    
  
  
  
  
  
    
  
  //$('#feature'+rownow+' .group')
   
   
  
   

  
  
   rowdiv++;
}


function changecelltour(actid)
{
nowactid=actid;
$(".wrpOutAddNewMyTrip").html('');
if(actid==1||actid==2)
{
pagemainset=1;

getactiondatatrip(actid);
}else
{
createactivitytour();
}
}

function getmapdatatouract(lat,lng)
{
var genmappoint={};
//genmappoint[0]=new google.maps.LatLng(valueobjdata.lat,valueobjdata.lng)
 var rowchecknow=0;
 
 if(typeof lat!= 'undefined')
 {



if(lat!='0.000000000000000'&&lat)
{
rowchecknow=1;
var latsetobj=new google.maps.LatLng(lat,lng);




$('.wrpAddNewActivitySet .mapactdata').gmap3({
                  marker:{ 
                    latLng:latsetobj,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('.wrpAddNewActivitySet input[name="lat"]').val(marker.position.lat());
                        $('.wrpAddNewActivitySet input[name="lng"]').val(marker.position.lng()); 
                        
                        
                        }
                        } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latsetobj
                        }
                      }
                });
                


}
 

 
 
 
 }
   //initialize($('#feature'+rownow+' .mapdata'));
     var handler = function() {
     
    if(rowchecknow==0)
    {
    rowchecknow=1;
     $('.wrpAddNewActivitySet .mapactdata').gmap3({
          getgeoloc:{
            callback : function(latLng){
            
              if (latLng){
              
              $('.wrpAddNewActivitySet input[name="lat"]').val(latLng.lat());
              $('.wrpAddNewActivitySet input[name="lng"]').val(latLng.lng()); 
              
               // $('#test1-result').html('localised !');
               
                $(this).gmap3({
                  marker:{ 
                    latLng:latLng,
                    options:{
                        draggable: true
                    },
                    events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('.wrpAddNewActivitySet input[name="lat"]').val(marker.position.lat());
                        $('.wrpAddNewActivitySet input[name="lng"]').val(marker.position.lng()); 
                        
                        
                        }
                        } 
                    
                    
                  },
                      map:{
                        options:{
                          zoom: 15,
                          center :latLng
                        }
                      }
                });
                
                
                $(this).unbind('click');
              } 
              else {

              }
            }
          }
        });
    }
        
      
     
     
     };
     
     $('.wrpAddNewActivitySet .mapclickdata').bind('click', handler);
   
   
     $('.wrpAddNewActivitySet input[name="detail"]').keyup(function() {
    
              if($(this).val()!='')
              {
              if(rowchecknow==0)
              {
              rowchecknow=1;
              }
             // console.log(1);
              
             $('.wrpAddNewActivitySet .mapactdata').gmap3({
             
             
              getlatlng:{
                address:  $(this).val(),
                callback: function(results){
                
                  
                  
                  if ( !results ) return;
                  
                  
                  $(this).gmap3({
                    clear: {
                      name:["marker"],
                      last: true
                    }
                  });
                 
//console.log(results[0].geometry);
                 $('.wrpAddNewActivitySet input[name="lat"]').val(results[0].geometry.location.lat());
                 $('.wrpAddNewActivitySet input[name="lng"]').val(results[0].geometry.location.lng()); 
                  
                  $(this).gmap3({
                    marker:{
                      latLng:results[0].geometry.location,
                      options:{
                        draggable: true
                        },
                      events:{
                        dragend: function(marker, event){
                        //$('input#lat').val( marker.position.lat() );
                        //$('input#lng').val( marker.position.lng() );
                        $('.wrpAddNewActivitySet input[name="lat"]').val(marker.position.lat());
                        $('.wrpAddNewActivitySet input[name="lng"]').val(marker.position.lng()); 
                        
                        
                        }
                        }   
                        
                        
                    },
                      map:{
                        options:{
                          zoom: 15,
                          center :results[0].geometry.location
                        }
                      }
                  });
                  
                  
                  
                }
              }
              
              
              
              });  
              }
     
     });
     
     
   
  


}

function createactivitytour()
{
var productxhr=$.get(serviceinfo+'getactivitylist', function(data) { 


var code = '<div class="wrpAddNewAct wrpAddNewActivitySet">\n';
code += '<div class="wrpBscAct clearfix clBd2 bdBtm">\n';
code += '<span class="hdBscAct clTxt2 fs03 boldGen">Basic Activity :</span>\n';
code += '<div class="wrpInBscAct">\n';
if(data.data.length)
{
arrayactive=data['data'];
$.each(data['data'], function(key, value) {


code += '<span class="bscAct clTxt2 fs03 clBg2" onclick="setactivitydata('+key+')">'+value.title+'</span>\n';


});

//code += '<span class="bscAct clTxt2 fs03 clBg2">Breakfast</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Lunch and Napping Time</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Dinner and Leisure Time</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Night Activities</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Room Time</span>\n';
}

code += '</div>\n';
code += '</div>\n';
code += '<div class="bodyAddAct">\n';
code += '<form class="wrpFrmGen" id="featureactivity">\n';
code += '<fieldset class="wrpFrmAddAct">\n';
code += '<div class="wrpOutImgAddNewAct">\n';
code += '<div class="wrpTtlImgAddAct">\n';
code += '<h2 class="ttlImgAddAct clTxt2 fs03">Thumbnail</h2>\n';
code += '<p class="rcmImgAddAct clTxt3 fs01">recommended size : 600px X 600px</p>\n';
code += '</div>\n';
code += '<div class="wrpImgAddAct image1">\n';
code += '<div class="imgAddAct clBg5 clBd2 bdFull plgAreaThumbnail">\n';
code += '</div>\n';
code += '<div class="addTnTl clBd2 bdBtm">\n';
code += '<div title="Browse" class="btnIco addImgTl clBd3 bdBtm uploadbutton">\n';
code += '<span class="ico icoAddImgTl"></span>\n';
code += '<div class="wrpUlFile">\n';
//code += '<input type="file" class="ulFile">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div title="Cloud" class="btnIco addCldTl clBd3 bdBtm cloudbutton cloud1">\n';
code += '<span class="ico icoAddCldTl"></span>\n';
code += '</div>\n';
code += '<div title="Link" class="btnIco addLnkTl clBd3 bdBtm linkbutton link1">\n';
code += '<span class="ico icoAddLnkTl"></span>\n';
code += '</div>\n';
code += '<div title="Remove" class="btnIco btnRmvTl deletebutton">\n';
code += '<span class="ico icoRmvTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpInfoAddNewAct">\n';
code += '<div class="wrpInpTtlAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Title</label><br>\n';
code += '<input type="text" name="title" class="inpTtlAddNewAct clBg5 clTxt3 fs02">\n';
code += '<input type="hidden" name="lat" >\n';
code += '<input type="hidden" name="lng" >\n';
code += '</div>\n';


code += '<div class="wrpInpLctAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Location</label><br>\n';
code += '<input type="text" name="detail" class="inpTtlAddNewAct clBg5 clTxt3 fs02">\n';
code += '</div>';


code += '<div class="wrpInpLctAddAct mapclickdata" >\n';
code += '<div class="wrpMapAtc clBg5 bdFull clBd2">\n';
code += '<div class="icoEditTl">\n';
code += '<span class="ico icoMapEditTl"></span>\n';
code += '</div>\n';
code += '<div class="mapAct mapactdata">\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';


code += '<div class="wrpInpDesAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Description</label><br>\n';
code += '<textarea  name="description" class="inpDesAddNewAct clBg5 clTxt3 fs02"></textarea>\n';
code += '</div>\n';
code += '<div class="wrpInpTimeAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Start Time</label><br>\n';
code += '<input type="text" class="inpTimeAddAct clBg5 clTxt3 fs02">\n';
code += '</div>\n';
code += '</div>\n';
code += '</fieldset>\n';
code += '</form>\n';
code += '</div>\n';
code += '</div>';
$(".wrpOutAddNewMyTrip").html(code);

getmapdatatouract();

var rownow='activity';
var rowgnow=1;
   $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(300,300,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];
         
         $('#feature'+rownow+' .image'+rowgnow2+' .plgAreaThumbnail').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         

         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);
         
         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);
         
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);
         
         
         $("#imgmid-"+setting.id).val(setting.imgmid);
         
         $("#simgmid-"+setting.id).val(imgmid2);
         
         
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);
         
         closepopup(); 
         
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //var rowgnow3=rowgnow;
          var rowgnow3=$(this).attr("class").split('cloud').pop();
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
         closepopup(); 

          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
           // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .deletebutton').click(function() {
   
   var rowgnow3=1;
   
   $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail a').remove();
   //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=1;
   
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         //$('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",filelink2+'?t='+Math.floor((Math.random()*100000)+1));
         
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
      //   $.colorbox.close("User added succesfully"); 
            closepopup();
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
          // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
   );
   
   });

   $("#feature"+rownow+' .inpTimeAddAct').datepicker( "destroy" ); 
   $("#feature"+rownow+' .inpTimeAddAct').timepicker();


});


}

var datesetact='';
var indexsetact=0;
function editactivitytourset(indexset,datecheckset)
{

var dataobj=objecttourcheck[datecheckset][indexset];
datesetact=datecheckset;
indexsetact=indexset;

var code = '<div class="ovlPopGen wrpAddAct wrpAddNewActivitySet">\n';
code += '<div class="popGen posPop">\n';


code += '<div class="topGen clBd2 bdBtm">\n';
code += '<div class="wrpTtlGen">\n';
code += '<h1 class="ttlGen clTxt2 fs05">Edit Activity</h1>\n';
code += '</div>\n';
code += '<div class="btnIco closeGen" onclick="$(\'.wrpAddNewActivitySet\').fadeOut()">\n';
code += '<span class="ico icoCloseGen"></span>\n';
code += '</div>\n';
code += '<div class="topBgGen clBg3"></div>\n';
code += '</div>';



code += '<div class="bodyGen clBg3">\n';
code += '<div class="bodyOutGen">\n';
code += '<div class="bodyInGen">\n';

code += '<div class="bodyAddAct clBg4 clBd2 bdFull">\n';
code += '<form class="wrpFrmGen" id="featureactivity">\n';
code += '<fieldset class="wrpFrmAddAct">\n';
code += '<div class="wrpOutImgAddNewAct">\n';
code += '<div class="wrpTtlImgAddAct">\n';
code += '<h2 class="ttlImgAddAct clTxt2 fs03">Thumbnail</h2>\n';
code += '<p class="rcmImgAddAct clTxt3 fs01">recommended size : 600px X 600px</p>\n';
code += '</div>\n';
code += '<div class="wrpImgAddAct image1">\n';
code += '<div class="imgAddAct clBg5 clBd2 bdFull plgAreaThumbnail">\n';
code += '</div>\n';
code += '<div class="addTnTl clBd2 bdBtm">\n';
code += '<div title="Browse" class="btnIco addImgTl clBd3 bdBtm uploadbutton">\n';
code += '<span class="ico icoAddImgTl"></span>\n';
code += '<div class="wrpUlFile">\n';
//code += '<input type="file" class="ulFile">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div title="Cloud" class="btnIco addCldTl clBd3 bdBtm cloudbutton cloud1">\n';
code += '<span class="ico icoAddCldTl"></span>\n';
code += '</div>\n';
code += '<div title="Link" class="btnIco addLnkTl clBd3 bdBtm linkbutton link1">\n';
code += '<span class="ico icoAddLnkTl"></span>\n';
code += '</div>\n';
code += '<div title="Remove" class="btnIco btnRmvTl deletebutton">\n';
code += '<span class="ico icoRmvTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpInfoAddNewAct">\n';
code += '<div class="wrpInpTtlAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Title</label><br>\n';
code += '<input type="text" value="'+dataobj.title+'" name="title" class="inpTtlAddNewAct clBg5 clTxt3 fs02">\n';
code += '<input type="hidden" name="lat" value="'+dataobj.lat+'" >\n';
code += '<input type="hidden" name="lng" value="'+dataobj.lng+'" >\n';
code += '</div>\n';


code += '<div class="wrpInpLctAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Location</label><br>\n';
code += '<input type="text" name="detail"  class="inpTtlAddNewAct clBg5 clTxt3 fs02">\n';
code += '</div>';


code += '<div class="wrpInpLctAddAct mapclickdata" >\n';
code += '<div class="wrpMapAtc clBg5 bdFull clBd2">\n';
code += '<div class="icoEditTl">\n';
code += '<span class="ico icoMapEditTl"></span>\n';
code += '</div>\n';
code += '<div class="mapAct mapactdata">\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>';


code += '<div class="wrpInpDesAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Description</label><br>\n';
code += '<textarea  name="description" class="inpDesAddNewAct clBg5 clTxt3 fs02">'+dataobj.desc+'</textarea>\n';
code += '</div>\n';
code += '<div class="wrpInpTimeAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Start Time</label><br>\n';
code += '<input type="text" value="'+dataobj.timeset+'" class="inpTimeAddAct clBg5 clTxt3 fs02">\n';
code += '</div>\n';
code += '</div>\n';
code += '</fieldset>\n';
code += '</form>\n';
code += '</div>\n';


code += '<div class="wrpBtnExpnPop">\n';
code += '<input type="button" value="Cancel" onclick="$(\'.wrpAddNewActivitySet\').fadeOut()" class="btnGen btnCncl clTxtW cutTxt clBgBt1 fs04">\n';
code += '<input type="submit" value="OK" onclick="edittourbyselectdata()" class="btnGen clTxtW cutTxt clBgSp2 fs04">\n';
code += '</div>';

code += '</div>';
code += '</div>';
code += '</div>';





code += '</div>';
code += '</div>';
$("#addpopimg").html(code);
$("#addpopimg .wrpAddNewActivitySet").fadeIn();
$(".wrpOutAddNewMyTrip").html('');
getmapdatatouract(dataobj.lat,dataobj.lng);

var rownow='activity';
var rowgnow=1;
 // console.log('#feature'+rownow+' .image'+rowgnow+' .uploadbutton');
   $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(300,300,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];
         
         $('#feature'+rownow+' .image'+rowgnow2+' .plgAreaThumbnail').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         

         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);
         
         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);
         
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);
         
         
         $("#imgmid-"+setting.id).val(setting.imgmid);
         
         $("#simgmid-"+setting.id).val(imgmid2);
         
         
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);
         
         closepopup(); 
         
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //var rowgnow3=rowgnow;
          var rowgnow3=$(this).attr("class").split('cloud').pop();
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
         closepopup(); 

          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
           // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .deletebutton').click(function() {
   
   var rowgnow3=1;
   
   $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail a').remove();
   //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=1;
   
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         //$('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",filelink2+'?t='+Math.floor((Math.random()*100000)+1));
         
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
      //   $.colorbox.close("User added succesfully"); 
            closepopup();
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
          // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
   );
   
   });

   $("#feature"+rownow+' .inpTimeAddAct').datepicker( "destroy" ); 
   $("#feature"+rownow+' .inpTimeAddAct').timepicker();


   
     $('#feature'+rownow+' .image'+rowgnow+' .plgAreaThumbnail').html('<a target="_blank" href="'+dataobj.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"><img  height="150" width="150" src="'+dataobj.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
    $('#feature'+rownow+' .image'+rowgnow+' input[name="imgmid[]"]').val(dataobj.imgmid);
    $('#feature'+rownow+' .image'+rowgnow+' input[name="simgmid[]"]').val(dataobj.simgmid);
    $('#feature'+rownow+' .image'+rowgnow+' input[name="filelinkcrop[]"]').val(dataobj.simg.newpath);
    $('#feature'+rownow+' .image'+rowgnow+' input[name="widthcrop[]"]').val(dataobj.simg.width);
    $('#feature'+rownow+' .image'+rowgnow+' input[name="heightcrop[]"]').val(dataobj.simg.height);



}

function savetourbyselectdata()
{
var datecheck=$('.dateTripTmlnAct').html();
var iddata=$('.dateTripTmlnAct').attr('id');
var iddata2=iddata.split("-"); 
var iddata3=iddata2[1]; 
if(typeof objecttourcheck[datecheck] != 'undefined')
{

}else
{

objecttourcheck[datecheck]=new Array();

}
var rownow=objecttourcheck[datecheck].length;


if(nowactid==1||nowactid==2)
{



$(".timeNewTrip.shwTimeNewTrip.w238:visible").each(function( index ) {

var idtimetrip=$(this).attr("id");
var rownid=idtimetrip.split("-"); 
var value= setproductidnow[rownid[1]];
var rownid=rownid[1];

objecttourcheck[datecheck][rownow]={};
objecttourcheck[datecheck][rownow]['productid']=value.productid;
objecttourcheck[datecheck][rownow]['title']=value.title;
objecttourcheck[datecheck][rownow]['desc']=value.description;
objecttourcheck[datecheck][rownow]['timeset']=$('#timestart-'+rownid).val();
objecttourcheck[datecheck][rownow]['type']=1;
objecttourcheck[datecheck][rownow]['simg']=value.simg;
objecttourcheck[datecheck][rownow]['imgmid']=value.imgmid;
objecttourcheck[datecheck][rownow]['simgmid']=value.simgmid;


var latsettrip=0;
var lngsettrip=0;

if(setproductidnow[rownid].plugins)
{
checkpoint=0;
$.each( setproductidnow[rownid].plugins, function( key, value ) {

if(value.plugname=="map")
{

checkpoint=1;
latsettrip=value.lat;
lngsettrip=value.lng;


}

});


}

objecttourcheck[datecheck][rownow]['lat']=latsettrip;
objecttourcheck[datecheck][rownow]['lng']=lngsettrip;




rownow++;

});
//console.log(objecttourcheck);

sorttimedata();

opentourdata(iddata3);



//console.log(objecttourcheck);

}
else if(nowactid==3)
{


if($('#featureactivity input[name="title"]').val()=="")
{
boxmsgdata('Please insert Title');
return false;
}
else if($('#featureactivity .inpTimeAddAct').val()=="")
{
boxmsgdata('Please insert Time');
return false;
}
else if($('#featureactivity input[name="filelinkcrop[]"]').val()=="")
{
boxmsgdata('Please insert Image');
return false;
}




objecttourcheck[datecheck][rownow]={};
objecttourcheck[datecheck][rownow]['productid']=0;
objecttourcheck[datecheck][rownow]['title']=$('#featureactivity input[name="title"]').val();
objecttourcheck[datecheck][rownow]['desc']=$('#featureactivity textarea[name="description"]').val();
objecttourcheck[datecheck][rownow]['timeset']=$('#featureactivity .inpTimeAddAct').val();
objecttourcheck[datecheck][rownow]['lat']=$('#featureactivity input[name="lat"]').val();
objecttourcheck[datecheck][rownow]['lng']=$('#featureactivity input[name="lng"]').val();
objecttourcheck[datecheck][rownow]['type']=2;
objecttourcheck[datecheck][rownow]['simg']={newpath:$('#featureactivity input[name="filelinkcrop[]"]').val(),width:$('#featureactivity input[name="widthcrop[]"]').val(),height:$('#featureactivity input[name="heightcrop[]"]').val()};
objecttourcheck[datecheck][rownow]['imgmid']=$('#featureactivity input[name="imgmid[]"]').val();
objecttourcheck[datecheck][rownow]['simgmid']=$('#featureactivity input[name="simgmid[]"]').val();

rownow++;

sorttimedata();

opentourdata(iddata3);

}

$(".ovlPopGen.wrpPopAddNewTrip").fadeOut();


}

function edittourbyselectdata()
{



var dataobj=objecttourcheck[datesetact][indexsetact];

var datecheck=$('.dateTripTmlnAct').html();
var iddata=$('.dateTripTmlnAct').attr('id');
var iddata2=iddata.split("-"); 
var iddata3=iddata2[1]; 



if($('#featureactivity input[name="title"]').val()=="")
{
boxmsgdata('Please insert Title');
return false;
}
else if($('#featureactivity .inpTimeAddAct').val()=="")
{
boxmsgdata('Please insert Time');
return false;
}
else if($('#featureactivity input[name="filelinkcrop[]"]').val()=="")
{
boxmsgdata('Please insert Image');
return false;
}




objecttourcheck[datesetact][indexsetact]={};
objecttourcheck[datesetact][indexsetact]['productid']=0;
objecttourcheck[datesetact][indexsetact]['title']=$('#featureactivity input[name="title"]').val();
objecttourcheck[datesetact][indexsetact]['desc']=$('#featureactivity textarea[name="description"]').val();
objecttourcheck[datesetact][indexsetact]['timeset']=$('#featureactivity .inpTimeAddAct').val();
objecttourcheck[datesetact][indexsetact]['lat']=$('#featureactivity input[name="lat"]').val();
objecttourcheck[datesetact][indexsetact]['lng']=$('#featureactivity input[name="lng"]').val();
objecttourcheck[datesetact][indexsetact]['type']=2;
objecttourcheck[datesetact][indexsetact]['simg']={newpath:$('#featureactivity input[name="filelinkcrop[]"]').val(),width:$('#featureactivity input[name="widthcrop[]"]').val(),height:$('#featureactivity input[name="heightcrop[]"]').val()};
objecttourcheck[datesetact][indexsetact]['imgmid']=$('#featureactivity input[name="imgmid[]"]').val();
objecttourcheck[datesetact][indexsetact]['simgmid']=$('#featureactivity input[name="simgmid[]"]').val();

//rownow++;

sorttimedata();

opentourdata(iddata3);





$("#addpopimg .wrpAddNewActivitySet").fadeOut();


}
 
function sorttimedata()
{

$.each(objecttourcheck, function(keydata, valueobjdata) {

           valueobjdata.sort(function(a, b) {
           return new Date( '1970/01/01 ' +a.timeset ) > new Date('1970/01/01 ' + b.timeset);
           });
           
           objecttourcheck[keydata]=valueobjdata;
           
});



}

var rowchecknowtour22=1;

function genmapnewtour(datachecktour)
{
var genmappoint={};
var genpoint={};  
var genpointarr=new Array();
var rowgenmap=0;


rowchecknowtour22++;

var datacheckcor;
var textsetmap='#pageaddfeature3 .itPlg.addMapPlg .plgArea';
if(datachecktour)
{
textsetmap='#main-middle .mapdataroute';
var datecheck=$('#main-middle .dateTripTmlnAct').html();
var producttourid=$('#main-middle input[name="nowproductid"]').val();

datacheckcor=objecttourcheck[producttourid];


}else
{
var datecheck=$('.dateTripTmlnAct').html();
datacheckcor=objecttourcheck;
}



//$.each($('.pointTrip.classpoint'), function(index ) {
if(typeof datecheck != 'undefined')
{
if(typeof datacheckcor[datecheck] != 'undefined')
{

if(datacheckcor[datecheck].length)
{
var rowdatacheck=0;
var rowdatacheck2=1;

var textset='';
$.each(datacheckcor[datecheck], function(keydata, valueobjdata) {
if(valueobjdata.type==1&&valueobjdata.lat!='0.000000000000000'&&valueobjdata.lat)
{
genmappoint[rowgenmap]=new google.maps.LatLng(valueobjdata.lat,valueobjdata.lng)
;
genpointarr[rowgenmap]={latLng:[valueobjdata.lat, valueobjdata.lng], data:valueobjdata.title,options:{icon: iconBase +pointData[rowgenmap]+'_maps.png'}};

genpoint[rowgenmap]={point:$(this).find('.clTxtW.fs02').html()};

rowgenmap++;

}else if(valueobjdata.type==2&&valueobjdata.lat!=''&&valueobjdata.lat)
{
genmappoint[rowgenmap]=new google.maps.LatLng(valueobjdata.lat,valueobjdata.lng)
;
genpointarr[rowgenmap]={latLng:[valueobjdata.lat, valueobjdata.lng], data:valueobjdata.title,options:{icon: iconBase +pointData[rowgenmap]+'_maps.png'}};

genpoint[rowgenmap]={point:$(this).find('.clTxtW.fs02').html()};

rowgenmap++;


}

});

}




//});


 //console.log(Object.keys(genmappoint).length);   
 //$('.itPlg.addMapPlg').show();

if(Object.keys(genmappoint).length>1)
{
  
  
  if(Object.keys(genmappoint).length>2)
  {
   var waypts=[];
   var rowwaypts=0;
   
//   console.log(genmappoint);
  $.each(genmappoint, function(index, value) {
       
         if(rowwaypts!=0&&rowwaypts!=(Object.keys(genmappoint).length-1))
         {
          waypts.push(
          {
                location:new google.maps.LatLng(value.lat(),value.lng()),
                stopover:true
          }
          );
         }
          
          
          rowwaypts++;
                     
        //alert(index + ': ' + value);
        
        
        });
   //console.log(waypts);     
    var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: false,  
        avoidTolls:true,
        waypoints:waypts,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };      
  
  
  }else
  {
  var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: true,  
        avoidTolls:true,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
  }

 $(textsetmap).gmap3('destroy');
$(textsetmap).gmap3({

  
   
  getroute:{
    options:objset,
    callback: function(results,results2){

  //   console.log(results);
//     console.log(results2);
           
       
      if(results)
      {
 
      $(this).gmap3({
        map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
        directionsrenderer:{
          options:{
            directions:results
          }
        }
      });
      
      }else
      {   

      $(this).gmap3({
      map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
         marker:{
    values:genpointarr,
    options:{
      draggable: false
    }
      
      }
      
      });
    
      }
    
    }
  }
});
}
else if(Object.keys(genmappoint).length==1)
{
$(textsetmap).gmap3('destroy');
 $(textsetmap).gmap3({
      map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
         marker:{
    values:genpointarr,
    options:{
      draggable: false
    }
      
      }
      
      });

}
else
{

$(textsetmap).gmap3('destroy');
$(textsetmap).html('');

}

 //console.log(objecttourcheck);
//return false;
return false;

}
else
{

$(textsetmap).gmap3('destroy');
$(textsetmap).html('');


}
}

}
var idnumset=0;
function openactivitytour(keydata)
{

if(checkeditset==2)
{
var datecheck=$('#rowdaynumset-'+idnumset).html();
datacheckcor=objecttourcheck;

}else
{
var datecheck=$('#main-middle #rowdaynumset-'+idnumset).html();

var producttourid=$('#main-middle input[name="nowproductid"]').val();
datacheckcor=objecttourcheck[producttourid];
}

if(typeof datacheckcor[datecheck] != 'undefined')
{

var setcheckatc=datacheckcor[datecheck][keydata];

$('.wrpPopActTrip .desAddGen').html(setcheckatc.title);
$('.wrpPopActTrip textarea').val(setcheckatc.desc);
$('.wrpPopActTrip').fadeIn();



}



}


function opentourdata(idnum,checkedit)
{
idnumset=idnum;
if(checkedit)
{
checkeditset=checkedit;
}else
{
checkeditset=2;
}
if(checkeditset==2)
{
$('.dateTripTmln').removeClass('dateTripTmlnAct');
$('#rowdaynumset-'+idnum).addClass('dateTripTmlnAct');

var datecheck=$('#rowdaynumset-'+idnum).html();

}else
{
$('#main-middle .dateTripTmln').removeClass('dateTripTmlnAct');
$('#main-middle #rowdaynumset-'+idnum).addClass('dateTripTmlnAct');

var datecheck=$('#main-middle #rowdaynumset-'+idnum).html();


}

var code='';
var datacheckcor;

if(checkeditset==2)
{
datacheckcor=objecttourcheck;
code = '<div class="pntTmln clearfix">\n';

code += '<div class="timeTmln">\n';
code += '<span class="fs03 boldGen">ADD</span>\n';
code += '</div>\n';

code += '<div class="dotTmln">\n';
code += '<span class="clBgBt1">\n';
code += '<em class="clTxtW boldGen fs03">+</em>\n';
code += '</span>\n';
code += '</div>\n';

code += '<div class="wrpActvtTmln clearfix">\n';

code += '<div class="triTmln">\n';
code += '<span class=""></span>\n';
code += '</div>\n';

code += '<div class="actvtTmln clBg5 clBd2 bdFull clearfix" onclick="openpopupnewtour('+idnum+')">\n';
code += '<a class="wrpBtnAddNewTrip">\n';
code += '<div class="imgActvtTmln">\n';
code += '<img src="/img/newtrip.png" alt="img">\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';

code += '</div>\n';


code += '</div>';
}else
{

var producttourid=$('#main-middle input[name="nowproductid"]').val();
datacheckcor=objecttourcheck[producttourid];




}

if(typeof datecheck != 'undefined')
{
if(typeof datacheckcor[datecheck] != 'undefined')
{
if(datacheckcor[datecheck].length)
{
var rowdatacheck=0;
var rowdatacheck2=1;

var textset='';
var linkset='';
var onclkset='';
var checkeditatc=0;
$.each(datacheckcor[datecheck], function(keydata, valueobjdata) {


if(valueobjdata.simg)
{

var objectset=convertTo12Hrs("February 04, 2011 "+(valueobjdata.timeset));

if(valueobjdata.type==1)
{
//console.log(valueobjdata.lat);
checkeditatc=0;
//textset=pointData[rowdatacheck]
//rowdatacheck++;


if(valueobjdata.lat!='')
{
textset=pointData[rowdatacheck];
rowdatacheck++;

}else
{

textset=rowdatacheck2;
rowdatacheck2++;
}

linkset=baseinfo+'/post/'+valueobjdata.productid;
onclkset='';
}
else
{
checkeditatc=1;
//console.log(valueobjdata.lat);
if(valueobjdata.lat!='')
{
textset=pointData[rowdatacheck];
rowdatacheck++;

}else
{

textset=rowdatacheck2;
rowdatacheck2++;
}


linkset='javascript:void(0)';
onclkset=' onclick="openactivitytour('+keydata+')" ';
}



code += '<div class="pntTmln clearfix" id="rowdatatour-'+keydata+'">\n';
code += '<div class="timeTmln">\n';
code += '<span class="fs03 boldGen">'+objectset.hour+':'+objectset.minutes+' '+objectset.ampmSwitch+'</span>\n';
code += '</div>\n';
code += '<div class="dotTmln">\n';
code += '<span class="clBgBt1">\n';
code += '<em class="clTxtW boldGen fs03">'+textset+'</em>\n';
code += '</span>\n';
code += '</div>\n';
code += '<div class="wrpActvtTmln clearfix">\n';
code += '<div class="triTmln">\n';
code += '<span class=""></span>\n';
code += '</div>\n';
code += '<div class="actvtTmln clBg5 clBd2 bdFull clearfix">\n';

code += '<a href="'+linkset+'"  '+onclkset+'>\n';

code += '<div class="imgActvtTmln">\n';



code += '<img alt="img" src="'+valueobjdata.simg.newpath+'">\n';
code += '</div>\n';
code += '<div class="cntntActvtTmln">\n';
code += '<div class="ttlLdTmln">\n';
code += '<span class="fs04 cutTxt boldGen">'+valueobjdata.title+'</span>\n';
code += '</div>\n';
code += '<div class="desLdTmln">\n';
code += '<span class="fs02 cutTxt">'+valueobjdata.desc+'</span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</a>\n';
code += '</div>\n';
if(checkeditset==2)
{
code += '<div class="edtTmln clBgBt2">\n';

code += '<div title="Remove" class="btnIco closeTl" onclick="deletethisrowdata('+keydata+',\''+datecheck+'\' )">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';


if(checkeditatc)
{


code += '<div title="Edit" class="btnIco edtCell wrpBtnEditTimeTmln" >\n';
code += '<span class="ico icoEdtCell" onclick="editactivitytourset('+keydata+',\''+datecheck+'\' )" ></span>\n';



code += '</div>\n';


}else
{


code += '<div title="Edit" class="btnIco edtCell wrpBtnEditTimeTmln" >\n';
code += '<span class="ico icoEdtCell" onclick="togglethisrowdata('+keydata+')" ></span>\n';

code += '<div class="edtTimeTmln clBg2 clBd2 bdFull">\n';
code += '<span class="fs03">Edit Time</span>\n';
code += '<input type="text" placeholder="Start Time" value="'+valueobjdata.timeset+'" class="inpAddCtnt w630 clBg5 clBd2 fs03 clTxt2">\n';
code += '<input type="button" onclick="edittourdatarow('+keydata+',\''+datecheck+'\' )" value="Submit" class="clBgSp1 clTxtW fs04">\n';
code += '</div>\n';

code += '</div>\n';



}



code += '</div>\n';
}
code += '</div>\n';
code += '</div>';

}


});

}

}


if(checkeditset==2)
{
$('.wrpTripTmln .wrpPntTmln').html(code);

$(".wrpTripTmln .wrpPntTmln .inpAddCtnt").timepicker();
genmapnewtour();
}else
{

$('#main-middle .wrpTripTmln .wrpPntTmln').html(code);
genmapnewtour(1);

}
}
}
function edittourdatarow(indexset,datecheckset)
{

var valuetour=$('#rowdatatour-'+indexset+' .inpAddCtnt').val();

objecttourcheck[datecheckset][indexset].timeset=valuetour;

var iddata=$('.dateTripTmlnAct').attr('id');
var iddata2=iddata.split("-"); 
var iddata3=iddata2[1]; 
sorttimedata();
opentourdata(iddata3);


$('#rowdatatour-'+indexset+' .edtTimeTmln').fadeOut();
}
function togglethisrowdata(indexset)
{
$('#rowdatatour-'+indexset+' .edtTimeTmln').fadeToggle();

}
//function editactivitytourset(indexset,datecheckset)
//{


//var dataobj=objecttourcheck[datecheckset][indexset];
//editactivitytourpop();


//}

Array.prototype.removedata = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
function deletethisrowdata(krow,datedata)
{

//delete objecttourcheck[datedata][krow];
//objecttourcheck[datedata].filter(function(a){return typeof a !== 'undefined';});

//objecttourcheck[datedata]=deleteFromArray(objecttourcheck[datedata], krow);

objecttourcheck[datedata].removedata(krow);

$('#rowdatatour-'+krow).remove();

var iddata=$('.dateTripTmlnAct').attr('id');
var iddata2=iddata.split("-"); 
var iddata3=iddata2[1]; 

sorttimedata();
opentourdata(iddata3);



}

function getactiondatatour(actid)
{
nowactid=actid;
if(actid==1)
{
userid=myuserid;
fav=0;

}
else if(actid==2)
{
userid=0;
fav=myuserid;

}


//$.post()
if(actid==1||actid==2)
{
if(pagemainset==1)
{
var code='<div class="wrpAddNewMyTrip clearfix" style="left: 0.5px;" ><div>';
$(".wrpOutAddNewMyTrip").html(code);
}

var productxhr=$.get(serviceinfo+'getproduct', { page:pagemainset,userid:userid,fav:fav,nopoi:1 }, function(data) { 


 if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         var code='';
         if(data.data.length>0)
         {
         
         $.each(data['data'], function(key, value) {
         setproductidnow[value.productid]=value;
         
         code += '<div class="wrpInCell wrpInCellNewTrip w238" id="setproduct-'+value.productid+'"  style="margin:1px;width:214px;height:214px">\n';
         code += '<div class="ovlCell w238"></div>\n';
        code += '<img width="238" height="238" alt="img" src="'+value.simg.newpath+'" class="imgCell w238">\n';
        code += '<div class="ldTtlCell fs09 clTxtCell cutTxt">'+value.title+'</div>\n';
        code += '<div class="authCell clearfix fs03 clTxtCell">\n';
        code += '<img width="36" height="36" alt="User Image" class="imgUserCell" src="'+value.userssimg.newpath+'">\n';
        code += '<span class="authName cutTxt">'+value.displayname+'</span>\n';
        code += '</div>\n';
        code += '<div class="wrpLikeCell">\n';
        code += '<i class="ico icoUnLikeW"></i>\n';
        code += '<span class="numLikeCell fs03 clTxtCell">'+value.countlike+'</span>\n';
        code += '</div>\n';
        code += '<form class="timeNewTrip addTimeNewTrip w238" id="timeNewTrip-'+value.productid+'" style="display:none">\n';
        code += '<div class="ovlTimeNewTrip"></div>\n';
        code += '<div class="wrpTimeNewTrip">\n';
        code += '<button type="button" class="btnGen clTxtW cutTxt clBgBt1 fs04" onclick="linkto(\''+baseinfo+'/'+value.link+'/'+value.productid+'\')">View</button>\n';
        code += '<input type="text" placeholder="Start Time" id="timestart-'+value.productid+'" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';
        code += '<button type="button" onclick="selectproducttrip('+value.productid+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
        code += '</div>\n';
        code += '</form>\n';
        
        
        code += '<form class="timeNewTrip shwTimeNewTrip w238" id="showtimeNewTrip-'+value.productid+'" style="display:none">\n';
        code += '<div class="wrpTimeNewTrip">\n';
        code += '<button type="button" class="btnGen btnDSlct clTxtW cutTxt clBgBt1 fs04" onclick="selecteditproducttrip('+value.productid+')">Deselect</button>\n';
        code += '<div class="shwTimeAddNewTrip fs18 clTxt2"><span id="shwTimeAddNewTrip-'+value.productid+'">10.00 AM</span></div>\n';
        code += '<button type="button" onclick="selecteditproducttrip('+value.productid+')" class="btnGen btnEditTime clTxtW cutTxt clBgSp2 fs04">Edit Time</button>\n';
        code += '</div>\n';
        code += '</form>';
        
        code += '</div>';
         
         
         });
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip").append(code);
         enddata=0;
         
         
         if(pagemainset==1)
         {
         
         
         $('.bodyAddNewTrip.clBg4.clBd2.bdFull').bind('scroll', function()
                              {
                                if($(this).scrollTop() + 
                                   $(this).innerHeight()
                                   >= $(this)[0].scrollHeight)
                                {
                                  
                                  if(enddata==0)
                                  {
                                    enddata=1;
                                    pagemainset++;
                                    getactiondatatrip(nowactid);
                                    
                                    //console.log('end reached');
                                  
                                  }
                                  
                                }
                              });
         }
         
         $('.wrpInCell.wrpInCellNewTrip.w238').each(function( index ) {
         
         
           $(this).hover(
                function() {
                   $(this).find('.timeNewTrip.addTimeNewTrip.w238').fadeIn();
              //  $( this ).append( $( "<span> ***</span>" ) );
                }, function() {
                    if($(this).find('.timeNewTrip.addTimeNewTrip.w238').hasClass("selectedtrip"))
                    {
                    
                    
                    }else
                    {
                    $(this).find('.timeNewTrip.addTimeNewTrip.w238').fadeOut();
                    }
                    
                    
                    
                    
              //  $( this ).find( "span:last" ).remove();
                }
                );
         
         
         });        
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").datepicker( "destroy" ); 
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").click(function() {
            var idtimetrip=$(this).attr("id");
             var rownid=idtimetrip.split("-"); 
             if($("#timeNewTrip-"+rownid[1]).hasClass("selectedtrip"))
             {
             
             }else
             {
             $("#timeNewTrip-"+rownid[1]).addClass("selectedtrip");
             
             }
             
         
            });
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").timepicker({onClose: function(dateText, inst) {

         var idtimetrip=$(this).attr("id");
             var rownid=idtimetrip.split("-"); 
             if($("#timeNewTrip-"+rownid[1]).hasClass("selectedtrip"))
             {
             $("#timeNewTrip-"+rownid[1]).removeClass("selectedtrip");
             }

        
               
                }
                
                }); 
         
         
         
         }else
         {
         if(pagemainset==1)
         {
         
         code += '<div class="nodata clTxt2 fs03">\n';
         if(actid==1)
         {
         code +='<span>No Post. Click <a class="clSp1"  href="javascript:void(0)" onclick="$(\'.btnAddSB.fs05.clBd2.cutTxt\').trigger(\'click\')">New Post</a> to create.</span>'
         }else
         {
         code += '<span>No Favorite.</span>\n';
         
         }
         
         code += '</div>';
         
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip").append(code);
         
         }
         
         enddata=1;
         
         }
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
       
         
         
         }



});
}
else
{

changecelltour(3);
}


}

function openpopupnewtour(daytrip)
{

daysettrip=daytrip;
pagemainset=1;
$(".ovlPopGen.wrpPopAddNewTrip").fadeIn();
//console.log(nowactid);
if(nowactid!=0)
{
getactiondatatour(nowactid);
}else
{
getactiondatatour(1);
}


}

var objecttourcheck2={};
var setindexobject=1;
function getformnewtour(dataplugin)
{

var code = '<div class="ldIt wrpPmtLd">\n';
code += '<div class="wrpPmtLd">\n';
code += '<h2 class="clTxt2 fs04">Duration</h2>\n';
code += '<div class="pmtLd">\n';
code += '<span class="boldGen">'+dataplugin.day+' Days '+dataplugin.night+' Night</span>\n';




if(dataplugin.enddate!="0000-00-00")
{

code += '(<span>'+dataplugin.startdate2+'</span>\n';
code += '<span> - </span>\n';
code += '<span>'+dataplugin.enddate2+'</span>)\n';
}else
{

var day0=dataplugin.startdate.split("-");

var d1 = new Date(day0[2],parseInt(day0[1],10)-1,parseInt(day0[0],10));


d1.setTime(d1.getTime() +  ((parseInt(dataplugin.day,10)-1) * 24 * 60 * 60 * 1000));


var enddateset2=d1.format("dd/mm/yyyy");




code += '(<span>'+dataplugin.startdate2+'</span>\n';
code += '<span> - </span>\n';
code += '<span>'+enddateset2+'</span>)\n';


}


code += '</div>\n';
code += '</div>\n';
code += '</div>';

if(dataplugin.currencyname!="")
{
code += '<div class="ldIt wrpOutPrcLd mgBtm20">\n';
code += '<div class="wrpPrcLd">\n';
code += '<h2 class="clTxt2 fs04">Price</h2>\n';
var priceset=dataplugin.price;
if(dataplugin.saleprice!="0.00")
{
priceset=dataplugin.saleprice;

}

code += '<span class="prcLd">'+priceset+' '+dataplugin.currencyname+'</span>\n';


code += '</div>\n';
code += '</div>';
}


code += '<div class="wrpCtcInfo">'+"\n";
code += '<div class="wrpHdInfoGen">'+"\n";
code += '<h2 class="clTxt2 fs04">Contact</h2>'+"\n";
code += '</div>'+"\n";
code += '<table class="tbGenInfo tbCtcLd tbAddCtnt clTxt3 fs03">'+"\n";
code += '<tbody>'+"\n";
if(dataplugin.facebook.indexOf("facebook")!=-1)
{
var datafacebook=dataplugin.facebook;
if(dataplugin.facebook.indexOf("http")==-1)
{
    datafacebook="http://"+dataplugin.facebook;

}


code += '<tr>\n';
code += '<th>Facebook</th>\n';
code += '<td><a href="'+datafacebook+'" target="_blank">'+datafacebook+'</a></td>\n';
code += '</tr>\n';
}
if(dataplugin.twitter.indexOf("twitter")!=-1)
{
var datatwitter=dataplugin.twitter;
if(dataplugin.twitter.indexOf("http")==-1)
{
    datatwitter="http://"+dataplugin.twitter;

}
code += '<tr>\n';
code += '<th>Twitter</th>\n';
code += '<td><a href="'+datatwitter+'" target="_blank">'+datatwitter+'</a></td>\n';
code += '</tr>\n';
}
if(dataplugin.googleplus.indexOf("google")!=-1)
{
var datatgoogleplus=dataplugin.googleplus;
if(dataplugin.googleplus.indexOf("http")==-1)
{
    datatgoogleplus="http://"+dataplugin.googleplus;

}

code += '<tr>\n';
code += '<th>Google+</th>\n';
code += '<td><a href="'+datatgoogleplus+'" target="_blank" >'+datatgoogleplus+'</a></td>\n';
code += '</tr>\n';

}
if(dataplugin.website)
{
if(ValidUrl(dataplugin.website))
{
code += '<tr>\n';
code += '<th>Website</th>\n';
code += '<td><a href="'+dataplugin.website+'" target="_blank" >'+dataplugin.website+'</a></td>\n';
code += '</tr>\n';
}
}
if(dataplugin.email)
{
if(validateEmail(dataplugin.email))
{
code += '<tr>\n';
code += '<th>Email</th>\n';
code += '<td>'+dataplugin.email+'</td>\n';
code += '</tr>\n';
}
}
if(dataplugin.phone)
{
code += '<tr>\n';
code += '<th>Phone</th>\n';
code += '<td>'+dataplugin.phone+'</td>\n';
code += '</tr>\n';
}
if(dataplugin.fax)
{
code += '<tr>\n';
code += '<th>Fax</th>\n';
code += '<td>'+dataplugin.fax+'</td>\n';
code += '</tr>\n';
}
if(dataplugin.etc)
{
if(ValidUrl(dataplugin.etc))
{

dataplugin.etc='<a href="'+dataplugin.etc+'" target="_blank" >'+dataplugin.etc+'</a>';

}
code += '<tr>\n';
code += '<th>ETC</th>\n';
code += '<td>'+dataplugin.etc+'</td>\n';
code += '</tr>\n';
}
code += '</tbody>\n';
code += '</table>\n';

code += '</div>\n';


if(Object.keys(dataplugin.objdata).length>0)
{

var arraydata=dataplugin;

code +='<div class="ldIt wrpMapLd clBg4 w640 mapdataroute" >'+"\n";
code += '<div class="icoDefLd">'+"\n";
code += '<span class="ico icoMapDefLd"></span>'+"\n";
code += '<span>Map</span>'+"\n";
code += '</div>'+"\n";
code += '</div>';



code += '<div class="ldIt wrpLdTripTmln clBg4 w640 clearfix">'+"\n";
code += '<div class="wrprTripTmln">'+"\n";
code += '<div class="btnDateTripTmln">'+"\n";

var rowdata=1;
var firsttime="dateTripTmlnAct";


objecttourcheck[arraydata.productid]={}

//echo "<pre>";
//print_r(arraydata['objdata']);
//echo "</pre>;";
//exit;

if(Object.keys(arraydata.objdata).length>0)
{

$.each(arraydata['objdata'], function(keydata, valueobjdata) {
//date=date("d/m/Y",strtotime("+".rowdata+" day",strtotime(arraydata['startdate2'])));
var date=keydata;
code += '<button id="rowdaynumset-'+rowdata+'" onclick="opentourdata('+rowdata+',1)" class="dateTripTmln clTxtW clBgBt1 fs04 '+firsttime+'">'+keydata+'</button>'+"\n";
firsttime='';

objecttourcheck[arraydata.productid][date]=new Array();
var rowdata2=0;

if(Object.keys(valueobjdata).length>0)
{


$.each(valueobjdata, function(keydata2, valueobjdata2) {

//console.log(valueobjdata2);

if(valueobjdata2['isactivity']=='1')
{
objecttourcheck[arraydata.productid][date][rowdata2]={};

objecttourcheck[arraydata.productid][date][rowdata2]['productid']=0;
objecttourcheck[arraydata.productid][date][rowdata2]['title']=valueobjdata2['title'];
objecttourcheck[arraydata.productid][date][rowdata2]['desc']=valueobjdata2['description'];
objecttourcheck[arraydata.productid][date][rowdata2]['timeset']=valueobjdata2['timeset'];
objecttourcheck[arraydata.productid][date][rowdata2]['type']=2;
objecttourcheck[arraydata.productid][date][rowdata2]['simg']=valueobjdata2['simg'];
objecttourcheck[arraydata.productid][date][rowdata2]['imgmid']=valueobjdata2['imgmid'];
objecttourcheck[arraydata.productid][date][rowdata2]['simgmid']=valueobjdata2['simgmid'];
objecttourcheck[arraydata.productid][date][rowdata2]['lat']=valueobjdata2['lat'];
objecttourcheck[arraydata.productid][date][rowdata2]['lng']=valueobjdata2['lng'];



}
else
{
if(valueobjdata2['data'])
{
objecttourcheck[arraydata.productid][date][rowdata2]={};

objecttourcheck[arraydata.productid][date][rowdata2]['productid']=valueobjdata2['data']['productid'];
objecttourcheck[arraydata.productid][date][rowdata2]['title']=valueobjdata2['data']['title'];
objecttourcheck[arraydata.productid][date][rowdata2]['desc']=valueobjdata2['data']['description'];
objecttourcheck[arraydata.productid][date][rowdata2]['timeset']=valueobjdata2['timeset'];
objecttourcheck[arraydata.productid][date][rowdata2]['type']=1;
objecttourcheck[arraydata.productid][date][rowdata2]['simg']=valueobjdata2['data']['simg'];
objecttourcheck[arraydata.productid][date][rowdata2]['imgmid']=valueobjdata2['data']['imgmid'];
objecttourcheck[arraydata.productid][date][rowdata2]['simgmid']=valueobjdata2['data']['simgmid'];

var latsettrip=0;
var lngsettrip=0;



if(Object.keys(valueobjdata2['data']['plugins']).length>0)
{


$.each(valueobjdata2['data']['plugins'], function(keydata3, valueplugins) {
if(valueplugins['plugname']=="map")
{


latsettrip=valueplugins['lat'];
lngsettrip=valueplugins['lng'];



}

});
}
objecttourcheck[arraydata.productid][date][rowdata2]['lat']=latsettrip;
objecttourcheck[arraydata.productid][date][rowdata2]['lng']=lngsettrip;
}

}

rowdata2++;
});
}


rowdata++;
});

}


code += '</div>'+"\n";

code += '<div class="wrpTripTmln">'+"\n";

code += '<div class="wrpInTripTmln">'+"\n";

code += '<div class="wrpBBTmln">'+"\n";
code += '<div class="bBTmln clBgBt2"></div>'+"\n";
code += '</div>'+"\n";

code += '<div class="wrpPntTmln">'+"\n";





code += '</div>'+"\n";
code += '</div>'+"\n";
code += '</div>'+"\n";
code += '</div>'+"\n";
code += '</div>';






//}

//data['str2']=code;
//data['target2']='secondtarget';


//data['script']='objecttourcheck='.json_encode(objecttourcheck)+";genmapnewtour();opentourdata(1,1);";


}

return code;


}
function saveformnewtour(id,plugid)    
{
    var obj={};  
    var id="formaddfeature";
    var alltime,openhours,closehours,infomation,sameaddressprofile,address,countryid,proid,disid,tumid,state,code,samecontactprofile,facebook,twitter,googleplus,email,website,phone,fax,etc,dayset,nightset,startdateset,enddateset,priceset,salepriceset,curidset,destinationset,day0,day1;
    
  samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').is(':checked');
        if(samecontactprofile)
        {
        samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').val();
        facebook="";
        twitter="";
        googleplus="";
        email="";
        website="";
        phone="";
        fax="";
        etc="";

        }else
        {
        samecontactprofile=0;
        facebook=$("#"+id+' input[name="facebook[]"]').val();
        twitter=$("#"+id+' input[name="twitter[]"]').val();
        googleplus=$("#"+id+' input[name="googleplus[]"]').val();
        email=$("#"+id+' input[name="email[]"]').val();
        website=$("#"+id+' input[name="website[]"]').val();
        phone=$("#"+id+' input[name="phone[]"]').val();
        fax=$("#"+id+' input[name="fax[]"]').val();
        etc=$("#"+id+' textarea[name="etc[]"]').val();



        }
        
        dayset=$("#"+id+' input[name="day[]"]').val();
        nightset=$("#"+id+' input[name="night[]"]').val();
        day0=$("#"+id+' input[name="startdate[]"]').val().split("/");
        enddateset=$("#"+id+' input[name="enddate[]"]').val();
        priceset=$("#"+id+' input[name="price[]"]').val();
        salepriceset=$("#"+id+' input[name="saleprice[]"]').val();
        curidset=$("#"+id+' select[name="curid[]"]').val();
        destinationset=$("#"+id+' select[name="destination"]').val();
        
        if(enddateset!="")
        {
        day1=enddateset.split("/");;
        enddateset=day1[2]+'-'+day1[1]+'-'+day1[0]
        
        }
        
        
        
        var objdata=new Array();
        var rowdataset=0;
        
        $.each($(".dateTripTmln"), function(index ) { 
        
        var datecheck=$(this).html();
        var n0=1;
        if(typeof objecttourcheck[datecheck] != 'undefined')
{  
       var day0=datecheck.split("/");;
       var startdateset2=day0[2]+'-'+day0[1]+'-'+day0[0]
        $.each(objecttourcheck[datecheck], function(keydata, valueobjdata) {
        
   //     var n0=$(this).find('input[name="settimedata[]"]').attr('alt');
        //console.log(n0);
//        n0=parseInt(n0,10);
        
        
        
       // console.log(n0);
        //console.log(day0);
        
        
        
//        var d1 = new Date(day0[2],parseInt(day0[1],10)-1,parseInt(day0[0],10));
//        d1.setTime(d1.getTime() +  ((n0-1) * 24 * 60 * 60 * 1000));
//        var startdateset2=d1.format("yyyy-mm-dd");
//        var timedateset2=$(this).find('input[name="settimedata[]"]').val()
        
        var timedateset2=valueobjdata.timeset;
        var timedateset2=valueobjdata.timeset;
        
        if(valueobjdata.type==2)
        {
        objdata[rowdataset]={isactivity:1,lat:valueobjdata.lat,lng:valueobjdata.lng,description:valueobjdata.desc,title:valueobjdata.title,simgmid:valueobjdata.simgmid,imgmid:valueobjdata.imgmid,day:n0,dateset:startdateset2,timeset:timedateset2+':00',plandate:startdateset2+' '+timedateset2+':00'
        
        };
        
        }
        else
        {
         
        objdata[rowdataset]={isactivity:0,sproductid:valueobjdata.productid,day:n0
        
        
        ,dateset:startdateset2,timeset:timedateset2+':00',plandate:startdateset2+' '+timedateset2+':00'
        
        };
        
        }
        
        rowdataset++;
        
        
        });
        n0++;
        
}
        
        
        });
        
        
        
        obj={plugid:plugid,proid:destinationset,day:dayset,night:nightset,startdate:day0[2]+'-'+day0[1]+'-'+day0[0],enddate:enddateset,price:priceset,saleprice:salepriceset,curid:curidset,samecontactprofile:samecontactprofile,facebook:facebook,twitter:twitter,googleplus:googleplus,email:email,website:website,phone:phone,fax:fax,etc:etc,objdata:objdata};
        
        
        return obj;

}



//function makeAdder(x) {
//  return function(y) {
//    return x + y;
//  };
//}

//var add5 = makeAdder(5);
//var add10 = makeAdder(10);

//console.log(add5(2));  // 7
//console.log(add10(2)); // 12

function editformnewtour(datarow)
{
objecttourcheck={};
var  arraydata=datarow;
if(Object.keys(arraydata.objdata).length>0)
{

$.each(arraydata['objdata'], function(keydata, valueobjdata) {
var date=keydata;
objecttourcheck[date]=new Array();

var rowdata2=0;

if(Object.keys(valueobjdata).length>0)
{


$.each(valueobjdata, function(keydata2, valueobjdata2) {


if(valueobjdata2['isactivity']=='1')
{
objecttourcheck[date][rowdata2]={};

objecttourcheck[date][rowdata2]['productid']=0;
objecttourcheck[date][rowdata2]['title']=valueobjdata2['title'];
objecttourcheck[date][rowdata2]['desc']=valueobjdata2['description'];
objecttourcheck[date][rowdata2]['timeset']=valueobjdata2['timeset'];
objecttourcheck[date][rowdata2]['type']=2;
objecttourcheck[date][rowdata2]['lat']=valueobjdata2['lat'];
objecttourcheck[date][rowdata2]['lng']=valueobjdata2['lng'];
objecttourcheck[date][rowdata2]['simg']=valueobjdata2['simg'];
objecttourcheck[date][rowdata2]['imgmid']=valueobjdata2['imgmid'];
objecttourcheck[date][rowdata2]['simgmid']=valueobjdata2['simgmid'];



}
else
{


objecttourcheck[date][rowdata2]={};
if(valueobjdata2['data'])
{
objecttourcheck[date][rowdata2]['productid']=valueobjdata2['data']['productid'];
objecttourcheck[date][rowdata2]['title']=valueobjdata2['data']['title'];
objecttourcheck[date][rowdata2]['desc']=valueobjdata2['data']['description'];
objecttourcheck[date][rowdata2]['timeset']=valueobjdata2['timeset'];
objecttourcheck[date][rowdata2]['type']=1;
objecttourcheck[date][rowdata2]['simg']=valueobjdata2['data']['simg'];
objecttourcheck[date][rowdata2]['imgmid']=valueobjdata2['data']['imgmid'];
objecttourcheck[date][rowdata2]['simgmid']=valueobjdata2['data']['simgmid'];

var latsettrip='';
var lngsettrip='';

if(Object.keys(valueobjdata2['data']['plugins']).length>0)
{


$.each(valueobjdata2['data']['plugins'], function(keydata3, valueplugins) {
if(valueplugins['plugname']=="map")
{


latsettrip=valueplugins['lat'];
lngsettrip=valueplugins['lng'];



}

});
}
objecttourcheck[date][rowdata2]['lat']=latsettrip;
objecttourcheck[date][rowdata2]['lng']=lngsettrip;
}

}

rowdata2++;
});
}



});

}


addformnewtour();

var rownow= rowdiv-1;
var rowgnow2=1;

    
    $('#formaddfeature input[name="day[]"]').val(datarow.day);
    $('#formaddfeature input[name="night[]"]').val(datarow.night);
    $('#formaddfeature input[name="startdate[]"]').val(datarow.startdate2);
    $('#formaddfeature input[name="enddate[]"]').val(datarow.enddate2);
    
    $('#formaddfeature input[name="price[]"]').val(datarow.price);
    $('#formaddfeature input[name="saleprice[]"]').val(datarow.saleprice);
    $('#formaddfeature select[name="curid[]"]').val(datarow.curid);
    
    $('#formaddfeature select[name="curid[]"]').val(datarow.curid);
    $('#formaddfeature select[name="destination"]').val(datarow.proid);
    
    
    
    //console.log(rownow);
    if(datarow.samecontactprofile!="0")
    {
    $('#formaddfeature input[name="samecontactprofile[]"]').trigger('click');
    }
    else
    {
    $('#formaddfeature input[name="facebook[]"]').val(datarow.facebook);
    $('#formaddfeature input[name="twitter[]"]').val(datarow.twitter);
    $('#formaddfeature input[name="googleplus[]"]').val(datarow.googleplus);
    $('#formaddfeature input[name="website[]"]').val(datarow.website);
    $('#formaddfeature input[name="email[]"]').val(datarow.email);
    $('#formaddfeature input[name="phone[]"]').val(datarow.phone);
    $('#formaddfeature input[name="fax[]"]').val(datarow.fax);
    $('#formaddfeature textarea[name="etc[]"]').val(datarow.etc);
    
    }
    
    

    



}

